<template>
    <div>
        <div class="pan-title">属性面板</div>
        <div class="simulated-constructor_container">
            <button @click="simulateProcesses(simulateData)">SIMULATED</button>
        </div>
    </div>
</template>

<script>
    export default {
        name: "simulated-construction",
        data:function () {
            return {
                model:GOLOAlBAL_OPEOBJ.bimModel,
                simulateData:{//
                    data:["0_196w0l5EXwXRwHBNTLqx",[ "0_196w0l5EXwXRwHNNTLqx", "0_196w0l5EXwXRwHJNTLqx"], "0_196w0l5EXwXRwH3NTLRi","0_196w0l5EXwXRwH7NTLRi", ["0_196w0l5EXwXRwHJNTLRi", "0_196w0l5EXwXRwHNNTLRi", "0_196w0l5EXwXRwHBNTLRi"], "0_196w0l5EXwXRwHFNTLRi"],
                    config:{
                        delay:12000
                    }
                }
            }
        },
        props:["currentTool"],
        methods:{
            /**
             * @param componentsSet
             */
            simulateProcesses(simulateSource){
                this.model.ghosted = true;
                var data = simulateSource.data || [];
                var config = simulateSource.config || {delay:20000};
                simulateSource.data.delay = config.delay;
                var queue = [simulateSource.data];
                while (queue.length){
                    //使用let不使用var，作用域问题
                    let componentOrGroup = queue.pop();
                    if(Array.isArray(componentOrGroup)&&componentOrGroup.length){
                        //计算出每个构件应该构件模拟修建的时间（根据等差数列，求出公差）
                        var len = componentOrGroup.length;
                        var duringTime = (2*componentOrGroup.delay)/(len*(len-1));
                        for(let i = 0; i < componentOrGroup.length; i ++){
                            if(Array.isArray(componentOrGroup[i])&&componentOrGroup[i].length){
                                componentOrGroup[i].delay = duringTime;
                                queue.push(componentOrGroup[i]);
                            }else{
                                new Promise(function (resolve,reject) {
                                    setTimeout(function () {
                                       // console.log(componentOrGroup[i]);
                                        //原始构件材质颜色
                                        var tempColor = [].concat(GOLOAlBAL_OPEOBJ.bimModel.objects[componentOrGroup[i]].colorize)[0];
                                        var preColor = [tempColor[0],tempColor[1],tempColor[2],tempColor[3]];
                                        GOLOAlBAL_OPEOBJ.bimModel.objects[componentOrGroup[i]].ghosted = false;
                                        //异步任务
                                        GOLOAlBAL_OPEOBJ.bimModel.objects[componentOrGroup[i]].colorize = [0.7058823704719543, 0.3490196168422699, 0.007843137718737125,1];
                                        resolve({preColor:preColor,item:componentOrGroup[i]});
                                    },(i+1)*duringTime)//此地方的时间控制需要斟酌
                                }).then(function (result) {
                                    GOLOAlBAL_OPEOBJ.bimModel.objects[result.item].colorize = data.preColor;
                                })
                            }
                        }
                    }
                }
            }
        },
        created(){

        },
        mounted(){

        }
    }
</script>

<style scoped>
    .pan-title{
        background: rgb(31,158,155);
        color: white;
        text-align: center;
        height: 40px;
        line-height: 40px;
    }
    .simulated-constructor_container{
        overflow-y: auto;
        height: 605px;
        color: white;
        background-color: rgba(3, 29, 35, 0.86) !important;
    }

    /*滚动条样式*/
    .simulated-constructor_container::-webkit-scrollbar {/*滚动条整体样式*/
        width: 6px;     /*高宽分别对应横竖滚动条的尺寸*/
        height: 6px;
    }
    .simulated-constructor_container::-webkit-scrollbar-thumb {/*滚动条里面小方块*/
        border-radius: 5px;
        -webkit-box-shadow: inset 0 0 5px rgba(228, 96, 50, 0.65);
        background: rgba(228, 96, 50, 0.65);
    }
    .simulated-constructor_container::-webkit-scrollbar-track {/*滚动条里面轨道*/
        -webkit-box-shadow: inset 0 0 5px rgba(228, 96, 50, 0.65);
        border-radius: 0;
        background: rgba(228, 96, 50, 0.1);
    }
</style>